package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WebUserWithdraw;
import com.ruoyi.system.service.IWebUserService;
import com.ruoyi.system.service.IWebUserWithdrawService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户提现申请Controller
 * 
 * @author wsliupan@126.com
 * @date 2021-06-06
 */
@Controller
@RequestMapping("/system/userWithdraw")
public class WebUserWithdrawController extends BaseController
{
    private String prefix = "system/userWithdraw";

    @Autowired
    private IWebUserWithdrawService webUserWithdrawService;
    @Autowired
    private IWebUserService iWebUserService;

    @RequiresPermissions("system:userWithdraw:view")
    @GetMapping()
    public String userWithdraw()
    {
        return prefix + "/userWithdraw";
    }

    /**
     * 查询用户提现申请列表
     */
    @RequiresPermissions("system:userWithdraw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebUserWithdraw webUserWithdraw)
    {
        startPage();
        List<WebUserWithdraw> list = webUserWithdrawService.selectWebUserWithdrawList(webUserWithdraw);
        return getDataTable(list);
    }

    /**
     * 导出用户提现申请列表
     */
    @RequiresPermissions("system:userWithdraw:export")
    @Log(title = "用户提现申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebUserWithdraw webUserWithdraw)
    {
        List<WebUserWithdraw> list = webUserWithdrawService.selectWebUserWithdrawList(webUserWithdraw);
        ExcelUtil<WebUserWithdraw> util = new ExcelUtil<WebUserWithdraw>(WebUserWithdraw.class);
        return util.exportExcel(list, "用户提现申请数据");
    }

    /**
     * 新增用户提现申请
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户提现申请
     */
    @RequiresPermissions("system:userWithdraw:add")
    @Log(title = "用户提现申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebUserWithdraw webUserWithdraw)
    {
        return toAjax(webUserWithdrawService.insertWebUserWithdraw(webUserWithdraw));
    }

    /**
     * 修改用户提现申请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebUserWithdraw webUserWithdraw = null;
        if(id == null || id ==  -1){
            webUserWithdraw = new WebUserWithdraw();
        }else{
            webUserWithdraw = webUserWithdrawService.getById(id);
        }
        mmap.put("webUserWithdraw", webUserWithdraw);
        mmap.put("user",iWebUserService.getById(webUserWithdraw.getUserId()));
        return prefix + "/edit";
    }

    /**
     * 修改保存用户提现申请
     */
    @RequiresPermissions("system:userWithdraw:edit")
    @Log(title = "用户提现申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebUserWithdraw webUserWithdraw)
    {
        return toAjax(webUserWithdrawService.updateWebUserWithdraw(webUserWithdraw));
    }

    /**
     * 删除用户提现申请
     */
    @RequiresPermissions("system:userWithdraw:remove")
    @Log(title = "用户提现申请", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webUserWithdrawService.deleteWebUserWithdrawByIds(ids));
    }
}
